/*****************************************************
 *
 *    This file is auto generated
 *
 *    SHA1: D3D175958AEB23D67FBA5AFFE98FD559C118DB9D
 *
 *****************************************************/

#include "mackinac.h"
#include "Mediator.h"

#define TARGET_ASSEMBLY L"B1_WebBridge.dll"
#define TYPE_PROXY L"SAP.BusinessOne.WebBridge.Framework.Proxy"
#define TYPE_XSENGINEBRIDGE L"SAP.BusinessOne.WebBridge.XSEngineBridge"
#define TYPE_IMCCBRIDGE L"SAP.BusinessOne.WebBridge.IMCCBridge"

namespace sap { namespace businessone { namespace webbridge {     
    /*
     * XSEngineBridge
     */
    unique_ptr<XSEngineBridge> XSEngineBridge::s_instance;
    XSEngineBridge::XSEngineBridge () : m_hash(0), m_mediator(nullptr)
    {
        Mediator* mediator = new Mediator(TARGET_ASSEMBLY, TYPE_PROXY, TYPE_XSENGINEBRIDGE);
        m_hash = mediator->create();
        m_mediator = mediator;
    }
    XSEngineBridge::~XSEngineBridge ()
    {
        if(m_mediator)
        {
            delete m_mediator;
            m_mediator = nullptr;
        }
    }
    XSEngineBridge& XSEngineBridge::instance()
    {
        if(!s_instance)
        {
            s_instance.reset(new XSEngineBridge ());
        }
        return *s_instance;
    }
    
    int XSEngineBridge::login (const wstring& uri, const wstring& user, const wstring& password) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"Login"))
            .put(uri)
            .put(user)
            .put(password)
        ;
        mediator->call(args);

        bool success;
        int ret = 0;

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.get(ret);
        }

        return ret;
    }
    
    
    wstring XSEngineBridge::getXAppList (const wstring& filter) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"GetXAppList"))
            .put(filter)
        ;
        mediator->call(args);

        bool success;
        wstring ret = L"";

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.extend().get(ret);
        }

        return ret;
    }
    
    
    
    /*
     * IMCCBridge
     */
    unique_ptr<IMCCBridge> IMCCBridge::s_instance;
    IMCCBridge::IMCCBridge () : m_hash(0), m_mediator(nullptr)
    {
        Mediator* mediator = new Mediator(TARGET_ASSEMBLY, TYPE_PROXY, TYPE_IMCCBRIDGE);
        m_hash = mediator->create();
        m_mediator = mediator;
    }
    IMCCBridge::~IMCCBridge ()
    {
        if(m_mediator)
        {
            delete m_mediator;
            m_mediator = nullptr;
        }
    }
    IMCCBridge& IMCCBridge::instance()
    {
        if(!s_instance)
        {
            s_instance.reset(new IMCCBridge ());
        }
        return *s_instance;
    }
    
    int IMCCBridge::login (const wstring& uri, const wstring& user, const wstring& password) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"Login"))
            .put(uri)
            .put(user)
            .put(password)
        ;
        mediator->call(args);

        bool success;
        int ret = 0;

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.get(ret);
        }

        return ret;
    }
    
    
    int IMCCBridge::deployPackage (const wstring& package) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"DeployPackage"))
            .put(package)
        ;
        mediator->call(args);

        bool success;
        int ret = 0;

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.get(ret);
        }

        return ret;
    }
    
    
    bool IMCCBridge::isCompanyEnabled () const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"IsCompanyEnabled"))
        ;
        mediator->call(args);

        bool success;
        bool ret = 0;

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.get(ret);
        }

        return ret;
    }
    
    
    wstring IMCCBridge::getMessageList (const wstring& filter, bool flag, int num, float f, double d, long long x) const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"GetMessageList"))
            .put(filter)
            .put(flag)
            .put(num)
            .put(f)
            .put(d)
            .put(x)
        ;
        mediator->call(args);

        bool success;
        wstring ret = L"";

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
            args.extend().get(ret);
        }

        return ret;
    }
    
    
    void IMCCBridge::test () const
    {
        Args args;
        Mediator* mediator = static_cast<Mediator*>(m_mediator);

        args.put(mediator->getType())
            .put(m_hash)
            .put(wstring(L"Test"))
        ;
        mediator->call(args);

        bool success;

        args.get(success);
        if(!success)
        {
            wstring err;
            args.extend().get(err);
        }
        else
        {
        }

    }
    
    
}}}